Skip to content

refactor(web): normalize Ask user message text extraction#1371

Open
whoisthey wants to merge 2 commits into
mainfrom
whoisthey/normalize-user-message-text-extraction
Open

refactor(web): normalize Ask user message text extraction#1371
whoisthey wants to merge 2 commits into
mainfrom
whoisthey/normalize-user-message-text-extraction

Conversation

@whoisthey

@whoisthey whoisthey commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Minor item in preparation of file/multi-part input in 'Ask' mode

Summary

The Ask chat feature represents messages as Vercel AI SDK UIMessages (SBChatMessage). Several call sites extracted the user's typed text with a message.parts[0] assumption, which silently drops the text if any non-text part (e.g. a file attachment) is ever first.

This PR introduces a shared getUserMessageText helper in packages/web/src/features/chat/utils.ts that finds the first text part, and replaces the brittle parts[0] extraction at all call sites with it.

This is behavior-preserving today (user messages currently have a single leading text part) and is a prerequisite for adding chat file attachments.

Summary by CodeRabbit

  • Bug Fixes
    • Chat previews, thread names, message history, and question snippets now handle messages with non-text content more reliably.
    • Empty or missing text is ignored, preventing incorrect descriptions or auto-generated names.
  • Chores
    • Consolidated chat message text extraction into a shared approach for more consistent behavior across the app.

Introduce a shared `getUserMessageText` helper in the chat utils and use it
everywhere the user's typed text is read from an `SBChatMessage`. Previously
several call sites assumed the text lived at `parts[0]`, which silently drops
the user's text if any non-text part (e.g. a file attachment) is ever first.

The helper finds the first text part instead, making extraction robust to
non-text parts. This is behavior-preserving today (user messages currently
have a single leading text part) and is a prerequisite for chat file
attachments.

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ca49cc27-3903-4437-9491-eb72b46e969a

📥 Commits

Reviewing files that changed from the base of the PR and between 5e1b8ee and ebcb2e5.

📒 Files selected for processing (7)
  • CHANGELOG.md
  • packages/web/src/app/(app)/chat/[id]/page.tsx
  • packages/web/src/ee/features/chat/agent.ts
  • packages/web/src/ee/features/chat/components/chatThread/chatThread.tsx
  • packages/web/src/ee/features/chat/components/chatThread/chatThreadListItem.tsx
  • packages/web/src/features/chat/utils.test.ts
  • packages/web/src/features/chat/utils.ts

Walkthrough

A shared helper now extracts user-message text from chat messages and replaces inline lookups in chat metadata, agent message history, chat naming, and thread previews. New tests cover text, non-text, and empty-part cases.

Changes

Shared chat user text extraction

Layer / File(s) Summary
Helper, tests, and changelog
packages/web/src/features/chat/utils.ts, packages/web/src/features/chat/utils.test.ts, CHANGELOG.md
getUserMessageText is added, covered by tests, and recorded in the changelog.
Metadata and message-history consumers
packages/web/src/app/(app)/chat/[id]/page.tsx, packages/web/src/ee/features/chat/agent.ts
generateMetadata and createMessageStream now use getUserMessageText for chat description and user-role message content.
Thread naming and preview text
packages/web/src/ee/features/chat/components/chatThread/chatThread.tsx, packages/web/src/ee/features/chat/components/chatThread/chatThreadListItem.tsx
Empty-chat naming and thread list preview text now derive from getUserMessageText.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • brendan-kellam
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: normalizing Ask user message text extraction in the web app.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch whoisthey/normalize-user-message-text-extraction

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Co-authored-by: Cursor <cursoragent@cursor.com>
@whoisthey whoisthey marked this pull request as ready for review June 26, 2026 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant